home *** CD-ROM | disk | FTP | other *** search
/ Aminet 40 / Aminet 40 (2000)(Schatztruhe)[!][Dec 2000].iso / Aminet / dev / c / ExtrasLib.lha / ExtrasLib / Source / EnqName.c < prev    next >
Encoding:
C/C++ Source or Header  |  2000-09-30  |  1.3 KB  |  63 lines

  1. #define __USE_SYSBASE
  2. //#include <clib/extras_protos.h>
  3. //#include <clib/extras/exec_protos.h>
  4. #include <exec/lists.h>
  5. #include <proto/exec.h>
  6. #include <string.h>
  7.  
  8. /****** extras.lib/EnqueueName ******************************************
  9. *
  10. *   NAME
  11. *       EnqueueName -- Place a Node in a sorted List.
  12. *
  13. *   SYNOPSIS
  14. *       EnqueueName(List,Node)
  15. *
  16. *       void EnqueueName(struct List *,struct Node*)
  17. *
  18. *   FUNCTION
  19. *       Place a Node in a sorted List prioritized by Node.ln_Name 
  20. *       and ln_Pri.
  21. *
  22. *   INPUTS
  23. *       List - pointer to a List to place Node into.
  24. *       Node - pointer to a Node to be placed in the List.
  25. *
  26. *   RESULT
  27. *       None.
  28. *
  29. *   NOTES
  30. *       The List must be presorted by ln_Name and ln_Pri.
  31. *       Every node must have its ln_Name field pointing to
  32. *       a NULL terminated string.
  33. *
  34. ******************************************************************************
  35. *
  36. */
  37.  
  38. void  EnqueueName(struct List *List,
  39.                   struct Node *Node)
  40. {
  41.   struct Node *n;
  42.   LONG cmp;
  43.   
  44.   if(List && Node)
  45.   {
  46.     n=List->lh_Head;
  47.     while(n->ln_Succ)
  48.     {
  49.       cmp=stricmp(Node->ln_Name,n->ln_Name);
  50.       if(cmp<=0)
  51.       {
  52.         if((cmp==0 && Node->ln_Pri>n->ln_Pri) || cmp<0)
  53.         { 
  54.           Insert(List,Node,n->ln_Pred);
  55.           return;
  56.         }
  57.       }
  58.       n=n->ln_Succ;
  59.     }
  60.     Insert(List,Node,n);
  61.   }
  62. }
  63.